//*********************************************************
// Output Registers used:
//   oPos - The vertex output position.
//   oT0  - original UV
//
//*********************************************************

// r1 = light_pos - pos
// oPos = MVP * p2
sub  r1, c[VL_MODEL_SPACE_LIGHT_POS], inPos	; r1 = Light vector
dp3 r2.x, r1, r1	; r2.x = length^2(r1)
rsq r2.y, r2.x		; r2.y = 1/length(r1)
rcp r2.z, r2.y		; r2.z = length(r1)
mul r1.xyz, r1, r2.y	; r1 = Light direction

sub r2.w, c[VL_PLIGHT_OORANGE_RANGE_SHADOWLENGTH_INTENSITY].z, r2.z	; r2.w = dist // light range - length(r1)
max r2.w, r2.w, c[CONSTANT_0_05_1_2].x		; clamp dist to 0..inf

dp3 r3.x, r1, inNormal			; r3.x = (Light direction * Normal)
slt r3.x, r3.x, c[CONSTANT_0_05_1_2].x	; r3.x = (r3.x < 0) ? 1 : 0

mul r2.xyz, r1, r2.w	;
mul r2.xyz, r2, r3.x	; light direction * dist * (r3.x < 0)

sub r1.xyz, inPos, r2
mov r1.w, c[CONSTANT_0_05_1_2].z

m4x4 r0, r1, c[MODEL_VIEW_PROJECTION]
mov oPos, r0

// oT0 = texcoord
mov oT0, inUV
mov oD0, c[CONSTANT_0_05_1_2].yyzy
mov oD1, c[CONSTANT_0_05_1_2].x
